package com.newtouch.bxzs.database.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.common.base.model.Position;
import com.newtouch.bxzs.database.model.bo.PositionDetailBO;
import com.newtouch.bxzs.database.model.bo.PositionListBO;
import com.newtouch.bxzs.database.model.bo.RoleBO;
import com.newtouch.bxzs.database.model.vo.UpdatePositionStateVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 岗位Mapper:
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/5 14:18</td>
 * <td>tianshangzhu</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author tianshangzhu
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface PositionMapper extends BaseMapper<Position> {
    /**
     * 查询所有岗位
     *
     * @param page         分页参数
     * @param keyWord      搜索词
     * @param terminalType 岗位所属终端
     * @param enableFlag 岗位启用标识
     * @return List<PositionListBO>
     */
    IPage<PositionListBO> listAllPosition(@Param("page") Page<PositionListBO> page, @Param("keyWord") String keyWord,
                                          @Param("terminalType") String terminalType, @Param("enableFlag") Integer enableFlag);

    /**
     * 查询岗位详情
     *
     * @param positionId 岗位id
     * @return PositionDetailBO
     */
    PositionDetailBO selectDetailById(@Param("positionId") String positionId);

    /**
     * 查询岗位对应的角色
     *
     * @param positionId 岗位id
     * @return List<RoleBO>
     */
    List<RoleBO> listRoleByPositionId(@Param("positionId") String positionId);


    /**
     * 删除RolePositionMap中间表中的岗位id对应的角色数据
     *
     * @param positionId 岗位id
     */
    @Delete("DELETE FROM ASSISTANT_ROLE_POSITION_MAP WHERE POSITION_ID = #{positionId}")
    void deleteByPositionId(@Param("positionId") String positionId);

    /**
     * 修改岗位状态
     *
     * @param updatePositionStateVo 参数
     */
    @Update("UPDATE ASSISTANT_POSITION SET IS_ENABLE = #{updatePositionStateVo.enableFlag} WHERE POSITION_ID = #{updatePositionStateVo.positionId}")
    void updateState(@Param("updatePositionStateVo") UpdatePositionStateVO updatePositionStateVo);

    /**
     * 批量删除岗位信息
     *
     * @param positionIdList 岗位id
     */
    void modifyValidStatus(@Param("positionIdList") List<String> positionIdList);

    /**
     * 判断要删除的岗位是否都是被禁用的
     *
     * @param positionIdList 岗位id
     * @return 统计数量
     */
    Integer checkIsEnable(@Param("positionIdList") List<String> positionIdList);
}
